package md.mru.core.service;

import md.mru.core.common.BaseDtoMapper;
import md.mru.core.domains.*;
import md.mru.core.dtos.*;
import md.mru.core.repositories.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author sergiu.marin
 * @since 01.04.2014
 */
@Service
public class SkillsDataService {

    @Autowired
    @Qualifier(value = "dtoMapper")
    private BaseDtoMapper mapper;
    @Autowired
    private EducationRepository educationRepository;
    @Autowired
    private EducationTypeRepository educationTypeRepository;
    @Autowired
    private EducationDomainRepository educationDomainRepository;
    @Autowired
    private ModernLanguageRepository modernLanguageRepository;
    @Autowired
    private LanguageRepository languageRepository;
    @Autowired
    private KnowledgeLevelRepository knowledgeLevelRepository;


    public List<EducationDto> getEducations(long folderId) {
        List<Education> educations = educationRepository.getEducations(folderId);
        return mapper.mapList(educations, EducationDto.class);
    }

    public long saveEducation(EducationDto educationDto) {
        Education education = mapper.map(educationDto, Education.class);
        return educationRepository.save(education).getId();
    }

    public void deleteEducation(long educationId) {
        educationRepository.delete(educationId);
    }

    public List<EducationTypeDto> getEducationTypes() {
        List<EducationType> educationTypes = educationTypeRepository.findAll();
        return mapper.mapList(educationTypes, EducationTypeDto.class);
    }

    public List<EducationDomainDto> getEducationDomains() {
        List<EducationDomain> educationDomains = educationDomainRepository.findAll();
        return mapper.mapList(educationDomains, EducationDomainDto.class);
    }

    public List<ModernLanguageDto> getModernLanguages(long folderId) {
        List<ModernLanguage> modernLanguages = modernLanguageRepository.getModernLanguage(folderId);
        return mapper.mapList(modernLanguages, ModernLanguageDto.class);
    }

    public long saveModernLanguage(ModernLanguageDto modernLanguageDto) {
        ModernLanguage modernLanguage = mapper.map(modernLanguageDto, ModernLanguage.class);
        return modernLanguageRepository.save(modernLanguage).getId();
    }

    public void deleteModernLanguage(long modernLanguageId) {
        modernLanguageRepository.delete(modernLanguageId);
    }

    public List<LanguageDto> getLanguages() {
        List<Language> languages = languageRepository.findAll();
        return mapper.mapList(languages, LanguageDto.class);
    }

    public List<KnowledgeLevelDto> getKnowledgeLevels() {
        List<KnowledgeLevel> knowledgeLevels = knowledgeLevelRepository.findAll();
        return mapper.mapList(knowledgeLevels, KnowledgeLevelDto.class);
    }
}
